<?php

namespace App\Models\Member;

use App\Models\BaseModel;
use App\Common\AliossHandler;
use Auth;

class Banner extends BaseModel
{
    protected $fillable = [
        'id', 'store_id', 'cover', 'url',
        'type', 'status', 'sort',
        'created_at', 'updated_at'
    ];

    public function getList($type)
    {
        $user = Auth::user()->toArray();
        $data = $this->where('store_id', $user['store_id'])
                 ->where('type', $type)
                 ->where('status', 1)
                 ->orderBy('sort', 'desc')
                 ->get()
                 ->toArray();

        foreach ($data as $key => $v) {
            $data[$key]['cover'] = AliossHandler::read('banner', $v['cover']);
        }

        return $data;
    }
}
